home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / INIT Shell Folder / INIT Example ƒ / AddResPatch.p next >
Text File  |  1990-05-28  |  2KB  |  60 lines

  1. unit INITShellResident;
  2. {Copyright © 1990, David B. Lamkins}
  3. {All rights reserved.}
  4.  
  5. {This unit must be compiled as a separate project, since code resource projects cannot have}
  6. {multiple segments.  We need this to be in a separate segment from the INIT loader since we}
  7. {depend upon the presence of a the standard code header as a place to stash a handle to any}
  8. {globals we may need for the patch.  Also, it is much easier and safer to size and detach a}
  9. {separate resource for the patch code than it is to play games with address arithmetic and}
  10. {call _BlockMove to make a copy of the patch code.  By convention this code resource will}
  11. {have a type of 'IRES' (see INITShellLoader).}
  12.  
  13. interface
  14.  
  15.     uses
  16.         INITShellGlobals, INITShellInlines, Retrace, SysEqu, ResCheck;
  17.  
  18.     procedure main;
  19.  
  20. implementation
  21.  
  22. {$D-}
  23. {$V-}
  24. {$R-}
  25.  
  26. {This is the resident code.  It may have local variables.  Global data must be accessed through}
  27. {the handle obtained from the GlobalsHandle function.  See the INITShellInlines unit for further}
  28. {programming details.}
  29.     procedure main;
  30. {Patch for AddResource(h: Handle; rType: ResType; id: INTEGER; name: STR255);}
  31. {The total size of all parameters on the stack is 14 bytes.}
  32. {The offsets to be used for the arguments are, from right to left:}
  33. {    name: 0, because it's the rightmost parameter}
  34. {    id: 4, add the on-stack size of 'name' (=4) to reach 'id'}
  35. {    rType: 6, add the on-stack size of 'id' (=2) to reach 'rType'}
  36. {    h:10, add the on-stack size of 'rType' (=4) to reach 'h'}
  37.         type
  38.             IntPtr = ^INTEGER;
  39.         var
  40.             theHandleArg: Handle;
  41.             theTypeArg: OSType;
  42.             theIDArg: INTEGER;
  43.             theNameArg: StringPtr;
  44.     begin
  45.         Break;        {debug stop, depending upon compile-time variable Debugging}
  46.         theHandleArg := Handle(LParam(10));
  47.         theTypeArg := OSType(LParam(6));
  48.         theIDArg := WParam(4);
  49.         theNameArg := Pointer(LParam(0));
  50.         if DangerousResource(theTypeArg, theIDArg, theNameArg, theHandleArg) then
  51.             begin
  52.                 IntPtr(ResErr)^ := fLckdErr;
  53.                 SysBeep(5);
  54.                 DeallocateAndReturn(14);
  55.             end
  56.         else
  57.             SetTrapExit;
  58.     end;
  59.  
  60. end.